package com.challenger.student.services.impl;

import java.util.List;
import java.util.Map;

import com.challenger.student.dao.ApplyDao;
import com.challenger.student.dao.LoanDataDao;
import com.challenger.student.dao.PointsDao;
import com.challenger.student.dao.StudentDao;
import com.challenger.student.dao.StudentUsrDao;
import com.challenger.student.entity.Apply;
import com.challenger.student.entity.LoanData;
import com.challenger.student.entity.Points;
import com.challenger.student.entity.Student;
import com.challenger.student.entity.StudentUsr;
import com.challenger.student.services.StudentService;
/**
 * 学生业务接口实现类
 * @author 古振猛 404879269@qq.com
 *
 */
public class StudentServiceImpl implements StudentService {

	private StudentDao studentDao;
	private StudentUsrDao studentUsrDao;
	private ApplyDao applyDao;
	private LoanDataDao loanDataDao;
	private PointsDao pointsDao;

	public void setLoanDataDao(LoanDataDao loanDataDao) {
		this.loanDataDao = loanDataDao;
	}

	public void setApplyDao(ApplyDao applyDao) {
		this.applyDao = applyDao;
	}

	public void setStudentDao(StudentDao studentDao) {
		this.studentDao = studentDao;
	}

	public void setStudentUsrDao(StudentUsrDao studentUsrDao) {
		this.studentUsrDao = studentUsrDao;
	}

	@Override
	public int updateStudentPersionalInfo(Student student) {
		return this.studentDao.updateStudentPersionalInfo(student);
	}

	@Override
	public List<Student> findStudentsByCoacherid(int coacherid) {
		return this.studentDao.findStudentsByCoacherid(coacherid);
	}

	@Override
	public List<StudentUsr> login(Map<String, Object> paraMap) {
		return this.studentUsrDao.login(paraMap);
	}

	@Override
	public List<StudentUsr> findStudentsByUsername(String username) {
		return this.studentUsrDao.findStudentsByUsername(username);
	}

	@Override
	public List<StudentUsr> findStudentsByIdnumber(String idnumber) {
		return this.studentUsrDao.findStudentsByIdnumber(idnumber);
	}

	@Override
	public int addStudentUsr(StudentUsr studentUsr) {
		int m = this.studentDao.insertIdNumber(studentUsr.getIdnumber());
		int n = this.studentUsrDao.addStudentUsr(studentUsr);
		if (m == 1 && n == 1) {
			return 1;
		} else {
			return 0;
		}
	}

	@Override
	public int updateStudentEduInfo(Student student) {
		return this.studentDao.updateStudentEduInfo(student);
	}

	@Override
	public int updateStudentFamilyInfo(Student student) {
		return this.studentDao.updateStudentFamilyInfo(student);
	}

	@Override
	public Student findStudentByIdnumber(String idnumber) {

		List<Student> students = this.studentDao
				.findStudentByIdnumber(idnumber);
		if (students.size() == 1) {
			return students.get(0);
		} else {
			return null;
		}

	}

	@Override
	public List<Apply> findAppliesByStuId(int sdtid) {
		return this.applyDao.findAppliesByStuId(sdtid);
	}

	@Override
	public List<LoanData> findLoanDatasByStuId(int sdtid) {
		return this.loanDataDao.findLoanDatasByStuId(sdtid);
	}

	@Override
	public int insertLoanData(LoanData loanData) {
		return this.loanDataDao.insertLoanData(loanData);
	}

	@Override
	public int updatePassword(StudentUsr studentUsr) {
		return this.studentUsrDao.updatePassword(studentUsr);
	}

	@Override
	public Student findStudentById(int sdtid) {
		return this.studentDao.findStudentById(sdtid);
	}

	@Override
	public int insertApply(Apply apply) {
		return this.applyDao.insertApply(apply);
	}

	public void setPointsDao(PointsDao pointsDao) {
		this.pointsDao = pointsDao;
	}

	@Override
	public List<Points> findPoints() {
		return this.pointsDao.findPoints();
	}

}
